import java.util.*;

public class oddEvenList {
    /**
     * 给定一个单链表，请设定一个函数，将链表的奇数位节点和偶数位节点分别放在一起，重排后输出。
        注意是节点的编号而非节点的数值。
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    public ListNode oddEvenList (ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode oddHead = head;
        ListNode odd = oddHead;
        ListNode evenHead = head.next;
        ListNode even = evenHead;
        head = head.next.next;
        while (head != null) {
            odd.next = head;
            odd = odd.next;

            even.next = head.next;
            even = even.next;

            if (head.next == null) {
                break;
            } else {
                head = head.next.next;
            }
        }
        odd.next = evenHead;
        return oddHead;
    }
}